﻿using System;
using System.Windows;
using eStock.Common;
using eStock.DataObjects;
using eStock.Properties;

namespace eStock
{
    /// <summary>
    /// Interaktionslogik für "App.xaml"
    /// </summary>
    public partial class App : Application
    {
        public App()
        {
            Exit += App_Exit;
        }

        void App_Exit(object sender, ExitEventArgs e)
        {
            if (Globals.Instance.DBLoaded && Settings.Default.updateOnClose)
            {
                try
                {
                    DatabaseObjects.Addresses.Update();
                    DatabaseObjects.Categories.Update();
                    DatabaseObjects.Trays.Update();
                    DatabaseObjects.Components.Update();
                    DatabaseObjects.Images.Update();
                    DatabaseObjects.Orders.Update();
                    DatabaseObjects.Projects.Update();
                    DatabaseObjects.Types.Update();
                }
                catch (Exception x)
                {
                    Logging.WriteError("Failed to update Database on closing: " + x.Message);
                }
            }
        }
    }
}
